{% extends 'oscar/dashboard/layout.html' %}
{% load category_tags %}
{% load i18n %}
{% load render_table from django_tables2 %}

{% block body_class %}{{ block.super }} catalogue{% endblock %}

{% block title %}
    {% trans "Categories" %} | {{ block.super }}
{% endblock %}

{% block breadcrumbs %}
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item">
                <a href="{% url 'dashboard:index' %}">{% trans "Dashboard" %}</a>
            </li>
            <li class="breadcrumb-item active" aria-current="page">
                {% trans "Categories" %}
            </li>
        </ol>
    </nav>
{% endblock %}

{% block header %}
    <div class="page-header">
        <a href="{% url 'dashboard:catalogue-category-create' %}" class="btn btn-primary float-right"><i class="fas fa-plus-circle"></i> {% trans "Create new category" %}</a>
        <h1>{% trans "Categories" %}</h1>
    </div>
{% endblock header %}

{% block dashboard_content %}
    {% if not request.GET.name %}
        <div class="alert alert-info">
            <div>{% trans "You are editing:" %}
                <strong><a href="{% url 'dashboard:catalogue-category-list' %}">{% trans "Home" %}</a></strong>
                {% if ancestors %}
                    &gt;
                    {% for ancestor in ancestors %}
                        <strong><a href="{% url 'dashboard:catalogue-category-detail-list' pk=ancestor.pk %}">{{ ancestor.name }}</a></strong>{% if not forloop.last %} > {% endif %}
                    {% endfor %}
                {% endif %}
            </div>
        </div>
    {% endif %}

    {% block search_categories %}
        <div class="table-header">
            <h3><i class="fas fa-search"></i> {% trans "Search Categories" %}</h3>
        </div>
        <div class="card card-body mb-0">
            <form id="search_category_form" method="get" class="form-inline" action="{% url 'dashboard:catalogue-category-list' %}">
                {% comment %}
                    Add the current query string to the search form so that the
                    sort order is not reset when searching.
                {% endcomment %}
                {% for name, value in request.GET.items %}
                    {% if name not in form.fields %}
                        <input type="hidden" name="{{ name }}" value="{{ value }}"/>
                    {% endif %}
                {% endfor %}

                {% include "oscar/dashboard/partials/form_fields_inline.html" with form=form %}
                <button type="submit" class="btn btn-primary" data-loading-text="{% trans 'Searching...' %}"><i class="fas fa-search"></i> {% trans "Search" %}</button>
                <a href="{% url 'dashboard:catalogue-category-list' %}" class="btn btn-secondary ml-1">{% trans "Reset" %}</a>
            </form>
        </div>
    {% endblock %}

    {% if category_list or child_categories %}
        <form method="post">
            {% csrf_token %}
            {% block bulk_action %}
                {% trans "Categories" as module_label %}
                {% include "oscar/dashboard/partials/bulk_actions.html" with page_objects_count=categories.page.object_list.data.count num_pages=categories.paginator.num_pages total_count=categories.paginator.count module=module_label %}
            {% endblock bulk_action %}
            {% block category_table %}
                {% render_table categories %}
            {% endblock category_table %}
        </form>
    {% elif request.GET.name %}
        <p>{% trans "No categories found." %}</p>
    {% endif %}

    {% if not child_categories %}
        <p>{% trans "There are no categories." %}</p>
    {% endif %}
{% endblock dashboard_content %}

{% block onbodyload %}
    {{ block.super }}
    oscar.dashboard.bulk_actions.init();
{% endblock onbodyload %}
